package com.alibaba.citrus.cr.mn.order.center.facade.function.common;

import com.alibaba.cz.base.tool.log.Log;
import com.epoch.app.mnordercenter.model.dto.SalesOrderAtomCreateResponse;

import java.util.List;

/**
 * @author zhangxiaorui
 * @ClassName OrderBizCreateService
 * @description: TODO
 * @date 2023/05/16 11:28
 * @version: 1.0
 */
public interface OrderBizCreateService<BizInput, AtomInput, BizOutput> {

    Log log = Log.getLogger(OrderBizCreateService.class);

    default List<BizOutput> batchCreate(BizInput bizBatchCreateRequest) {
        try {
            // 1.0 参数预处理，订单头公共属性 同步更新至 订单明细
            preHandleRequestParams(bizBatchCreateRequest);

            // 2.0 业务校验-防腐适配处理 以及基础数据转换
            List<SalesOrderAtomCreateResponse> responses = assembleBizBaseInfo(bizBatchCreateRequest);

            // 3.0 商业Request->原子Request
            AtomInput atomCreateRequest = convertAtomRequest(bizBatchCreateRequest);

            // 4.0 调用订单原子创建能力
            return processAtomAbility(atomCreateRequest, responses);
        } catch (Exception e) {
            log.error("OrderBizCreateService#batchCreate error", e);
            throw e;
        }
    }

    void preHandleRequestParams(BizInput bizBatchCreateRequest);

    List<SalesOrderAtomCreateResponse> assembleBizBaseInfo(BizInput bizOrderCreateList);

    AtomInput convertAtomRequest(BizInput bizBatchCreateRequest);

    List<BizOutput> processAtomAbility(AtomInput atomCreateRequest, List<SalesOrderAtomCreateResponse> responses);
}
